var pageSize = 10;
//职称类别
var resourceTypeMap = {};
var rowid=null;
$(document).ready(function(){
	//表格初始化
	initTable();
	genDictSelect('studyCode','study_type','1');
	resourceTypeMap=getTransParam('studyCode');
	//事件绑定
	eventBind();
});

//事件绑定
function eventBind(){
	//带有分页信息的查询
	$("#queryBtn").click(pageQuery).click();
	$("#showBtn").on('click',function(){
		showFormDialog();
	});
}

//表格初始化
function initTable(){
	$('#studyListTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			query(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
		}
	});
}

//带有分页信息的查询
function pageQuery(){
	query(1, pageSize);
};

//分页查询
function query(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#showForm").collect()
	}
	
	$.getApiClient('/study/listShowOnline').post(queryCondition).done(function(data){
	    $('#studyListTable').bootstrapTable('load', data.payload);
	});
};

//发布
function showAgreeDialog(){
	if(rowid==null){
		customTimeOutDialog('信息提示','请选择课程后进行发布',null,2000);
	}else{
		$.getApiClient('/study/showOnline/{id}').setQuery({id:rowid}).put().done(function(data){
			if(data.code == "0"){
				BootstrapDialog.closeAll();
				customTimeOutDialog('信息提示','课程发布完成',null,2000);
				pageQuery();
			}else{
				customAlertDialog(data.message, '错误提示', null, null);
			}
		});
	}
}

//查看详情
function showDetailFormDialog(row){
	customRemoteUrlDialog('课程详情','/page/business/study/showView?Id='+row.id,null);
}

function showFormDialog(){
	customRemoteUrlDialog('课程详情','/page/business/study/showForm',null);
}


//操作列
function operateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="查看详细"><i class="fa fa-edit"></i>查看详细</a>');
	return operates.join('');
};


operateEvents = {
	'click .edit' : function(e, value, row, index) {
		showDetailFormDialog(row);
	}
};